<template>
	<view>
		<view style="margin-top: 100rpx;" >
			<view style="z-index: 999;position: absolute;top: 60rpx;left: 325rpx;">
				<u-avatar size="100" style="background-color: white;" :src="logo"></u-avatar>
			</view>
			<u-card box-shadow="5rpx 5rpx 10rpx #c8c9cc" :head-style="{padding: '0',paddingBottom: '30rpx'}"
				border-radius="30">
				<view class="" slot="head" style="text-align: center;color: black;font-size: 35rpx;font-weight: bold;">
					<view style="margin-top: 75rpx;" v-if="employe">{{employe.company.company_name}}</view>
				</view>
				<view class="" slot="body">
					<view>
						<u-form :model="form" ref="uForm" label-width="200" :error-type="['border-bottom']">
							<u-form-item label="缴纳金额" prop="deposit_pay_amont">
								<view style="display: flex;justify-content: flex-end;text-align: right;">
									<u-input v-model="form.deposit_pay_amont" type="digit"  placeholder="1～10000" input-align="right" :clearable="false"/>
									<view style="color: black;font-weight: bold;margin-left: 20rpx;">元</view>
								</view>
							</u-form-item>
							<u-form-item label="退还期限" prop="deposit_back_term">
								<view style="display: flex;justify-content: flex-end;text-align: right;">
									<u-input v-model="form.deposit_back_term" type="number" placeholder="请输入退还期限" input-align="right" :clearable="false"/>
									<view style="color: black;font-weight: bold;margin-left: 20rpx;">天</view>
								</view>
							</u-form-item>
							<u-form-item label="客户姓名" prop="custom_name">
								<view style="display: flex;white-space: nowrap">
									<u-input style="width: 100%;" v-model="form.custom_name"  placeholder="请输入客户姓名" input-align="right" :clearable="false"/>
									<text style="color:#2979ff;margin-left: 20rpx;" @click="toSelectOrdersPage()">选择</text>
								</view>
							</u-form-item>
							<u-form-item label="客户手机号" prop="custom_tel">
								<u-input v-model="form.custom_tel" type="number" placeholder="请输入客户手机号" input-align="right" :clearable="false"/>
							</u-form-item>
							<u-form-item label="车牌号" prop="car_num">
								<view style="display: flex;white-space: nowrap">
									<u-input style="width: 100%;" v-model="form.car_num"  placeholder="请输入车牌号" input-align="right" :clearable="false"/>
									<text style="color:#2979ff;margin-left: 20rpx;" @click="toSelectCarPage()">选择</text>
								</view>
							</u-form-item>

							<view style="width: 100%;">
								<u-button @click="submit" type="primary">生成二维码</u-button>
							</view>
						</u-form>
					</view>
					<view style="margin-top: 20rpx;">
						<u-alert-tips type="warning" title="自2025年8月14日起，您发起的每笔扣款将收取2%的佣金" ></u-alert-tips>
					</view>
				</view>
				
			</u-card>

		</view>
		<u-toast ref="uToast"></u-toast>
		<myModal ref="myModal"></myModal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logo: require('@/static/index/yajinjianmian.png'),
				employe: null,
				form: {
					deposit_pay_amont: '',
					deposit_back_term: '',
					custom_id:'',
					custom_name:'',
					custom_tel:'',
					car_id:'',
					car_pool_id:'',
					car_num:'',
					car_type_id:'',
					car_type_name:''
				},
				rules: {
					deposit_pay_amont: [{
						required: true,
						message: '请输入支付金额',
						trigger: ['blur', 'change']
					}],
					deposit_back_term: [{
						required: true,
						message: '请输入退还金额',
						trigger: ['blur', 'change']
					}],
					custom_name: [{
						required: true,
						message: '请输入客户姓名',
						trigger: ['blur', 'change']
					}],
					custom_tel: [{
						required: true,
						message: '请输入客户手机号',
						trigger: ['blur', 'change']
					}],
					car_num: [{
						required: true,
						message: '请输入车牌号',
						trigger: ['blur', 'change']
					}],
					
				}
			}
		},
		mounted() {
			var that=this;
			this.getCurrentEmploye();
			uni.$on("returnCustom",function(custom){
				that.form.custom_id=custom.custom_id;
				that.form.custom_name=custom.custom_name;
				that.form.custom_tel=custom.custom_tel;
			});
			uni.$on("returnCar",function(car){
				console.log(car);
				that.form.car_id=car.car_id;
				that.form.car_pool_id=car.car_pool_id;
				that.form.car_num=car.car_num;
				that.form.car_type_id=car.car_type_id;
				that.form.car_pool_id=car.car_pool_id;
				that.form.car_type_name=car.myType.cxmc;
			});
			
		},
		methods: {
			toSelectOrdersPage(){
				uni.navigateTo({
					url:'/pages/returnCustom/returnCustom'
				})
			},
			toSelectCarPage(){
				uni.navigateTo({
					url:'/pages/selectCarAndReturn/selectCarAndReturn'
				})
			},
			
			getCurrentEmploye() {
				var that = this;
				this.$http.post('/employe/getCurEmployeInfo', {}, (res) => {
					that.employe = res.data.result;
				});
			},
			submit() {
				var that=this;
				var form=that.form;
				form.deposit_pay_type=1;
				form.deposit_from_type=2;
				form.deposit_type=3;
				this.$refs.uForm.validate(valid => {
					if (valid) {
						that.$http.post('/depositPay/insert', form, (res) => {
							console.log("请求成功了");
							if (res.data.success) {
								console.log(that.$refs.uToast);
								that.$refs.uToast.show({
									title: '添加押金成功',
									type: "success"
								});
								uni.redirectTo({
									url:'/pages/depositQrCodeShow/depositQrCodeShow?deposit_pay_id='+res.data.result.deposit_pay_id
								})
							} else {
								that.$refs.myModal.show('登录失败', res.data.result.message);
							}
						});
					}else{
						console.log("验证失败");
					}
				});
			},
			onReady() {
				this.$refs.uForm.setRules(this.rules);
			}
		}
	}
</script>

<style>
	
</style>